package es.ats.codington.festival.daos;
/**
 */
import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import es.ats.codington.festival.interfaces.daos.IEventDAO;
import es.ats.codington.festival.interfaces.daos.IEventSignUpDAO;
import es.ats.codington.festival.interfaces.daos.IPlaceDAO;
import es.ats.codington.festival.interfaces.daos.IVisitorDAO;
import es.ats.codington.festival.utils.FERSDataConnection;
/**
 * 
 * @author Codington_RED
 *
 */
public class ManagerDAO {
	
	private DataSource dataSource;
	private Properties queryProperties;
	private JdbcTemplate jdbcTemplate;
	
	Connection conn;

	
	/**
	 * 
	 * @param queryProperties
	 */
	public void setQueryProperties(Properties queryProperties) {
		this.queryProperties = queryProperties;
	}


	/**
	 * 
	 * @param jdbcTemplate
	 */
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate){  
		this.jdbcTemplate = jdbcTemplate;  
	}  

	
	/**
	 * 
	 * @param dataSource
	 */
	public void setDataSource(DataSource dataSource) {  
		this.jdbcTemplate = new JdbcTemplate(dataSource);  
	}  
	
	
	/**
	 * Return an instance of JdbcTemplate
	 * 
	 * @return JdbcTemplate
	 */
	public JdbcTemplate getTemplate(){  
		return jdbcTemplate;  
	}  
	
	
	/**
	 * 
	 * @return VisitorDAOImpl
	 */
	public IVisitorDAO getVisitorDAO(){
		return new VisitorDAOImpl(jdbcTemplate, queryProperties);
	}
	/**
	 * 
	 * @return EventDAOImpl
	 */
	public IEventDAO getEventDAO() {
		return new EventDAOImpl(jdbcTemplate, queryProperties);
	}
	
	/**
	 * 
	 * @return EventSignUpDAOImpl
	 */
	
	public IEventSignUpDAO getEventSignUpDAO(){
		return new EventSignUpDAOImpl(jdbcTemplate, queryProperties);
	}
	
	/**
	 * 
	 * @return PlaceDAOImpl
	 */
	
	public IPlaceDAO getPlaceDAO(){
		return new PlaceDAOImpl(jdbcTemplate, queryProperties);
	}
	
	/**
	 * Closes Connection 
	 */
	
	public void closeConnection(){
		FERSDataConnection.commit(conn); 
		FERSDataConnection.closeConnection(conn);
	}
	
	/**
	 * Closes Error
	 */
	
	public void closeError(){
		FERSDataConnection.rollback(conn);
		FERSDataConnection.closeConnection(conn);
	}

	/**
	 * Closes Connection with commit
	 */

	public void closeConnectionWithCommit() {
		// TODO Auto-generated method stub
		FERSDataConnection.commit(conn);
		FERSDataConnection.closeConnection(conn);
		
	}
	/**
	 * Closes Connection with RollBack
	 */

	public void closeConnectionWithRollBack() {
		// TODO Auto-generated method stub
		FERSDataConnection.rollback(conn);
		FERSDataConnection.closeConnection(conn);
		
	}
	
}
